package com.example.appointment.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.appointment.R;
import com.example.appointment.meta.TestVO;
import com.example.appointment.meta.TestVO1;
import com.tencent.connect.common.Constants;
import com.tencent.connect.share.QQShare;

import de.greenrobot.event.EventBus;

/**
 * Created by Admin on 2016/9/16.
 */
public class LoginActivity extends BaseLoginActivity {
    private Button qqLoginBtn, weChatBtn;
    private TextView textView;
    private Button loginbtn;
    private int shareType = QQShare.SHARE_TO_QQ_TYPE_DEFAULT;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setnotificationColore(R.color.colorAccent);//設置导航栏顔色
        setContentView(R.layout.activity_login);
        qqLoginBtn = (Button) findViewById(R.id.login_btn);
        weChatBtn = (Button) findViewById(R.id.weChat_btn);
        loginbtn = (Button) findViewById(R.id.mob_login);
        textView = (TextView) findViewById(R.id.login_message);

//        mTencent = AppointmentApplication.getInstance().getmTencent();

        qqLoginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                initTencent();
//                login();
//                getUserInfoWithListener();
//                getUserInfo();
                startActivity(new Intent(LoginActivity.this, PerfectInformationActivity.class));
            }
        });

        //退出登陆
        weChatBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //调起微信登陆
//                final SendAuth.Req req = new SendAuth.Req();
//                req.scope = "snsapi_userinfo";
//                req.state = "carjob_wx_login";
//                AppointmentApplication.api.sendReq(req);
//                onClickShare();
            }
        });
        loginbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //测试eventbus的相关的操作
                EventBus.getDefault().post(new TestVO("主线程发的消息1"));
                EventBus.getDefault().post(new TestVO1("主线程发的消息2"));
            }
        });
        initToKen();
        //eventbus
//        代码实现 （本例是两个Fragment交互， 也可以是Service，Activity，Fragment以及任意类之间交互）

    }

    public void initToKen() {
//        getWithoutProgress("http://121.40.221.223:5002/qiniu/bucket/avator/token", null, new HttpCallbackListener() {
//            @Override
//            public void onRequestSuccess(String result, Object requestData) {
//                Log.i("qiniu", result);
////                com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result);
////                strToken = jsonObject.getString("token");
//            }
//
//            @Override
//            public void onServerError(String result, int statusCode) {
//
//            }
//        });
    }

    @Override
    protected void showMessage(String s) {
        textView.setText(s);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    private void onClickShare() {
        final Bundle params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
        params.putString(QQShare.SHARE_TO_QQ_TITLE, "要分享的标题");
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, "要分享的摘要");
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, "http://www.qq.com/news/1.html");
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, "http://imgcache.qq.com/qzone/space_item/pre/0/66768.gif");
        params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "测试应用222222");
//        params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, "其他附加功能");
//        mTencent.shareToQQ(LoginActivity.this, params, qqShareListener);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == Constants.REQUEST_QQ_SHARE) {
//            Tencent.onActivityResultData(requestCode, resultCode, data, qqShareListener);
        }
    }

//    IUiListener qqShareListener = new IUiListener() {
//        @Override
//        public void onCancel() {
//            if (shareType != QQShare.SHARE_TO_QQ_TYPE_IMAGE) {
//                ToastUtil.showToast(LoginActivity.this, "取消", 500);
//            }
//        }
//
//        @Override
//        public void onComplete(Object response) {
//            // TODO Auto-generated method stub
//            ToastUtil.showToast(LoginActivity.this, response.toString(), 500);
//        }
//
//        @Override
//        public void onError(UiError e) {
//            // TODO Auto-generated method stub
//            ToastUtil.showToast(LoginActivity.this, e.errorMessage, 500);
//        }
//    };

//    /**
//     * 手机登录
//     *
//     * @param view
//     */
//    @OnClick(R.id.mob_login)
//    public void moblogin(View view) {
//        LoginActivity.this.startActivity(new Intent(LoginActivity.this, MobloginActivity.class));
//    }

}
